from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"$\int _{0}^{\pi }\dfrac{1}{1+\cos ^{2}x}dx $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
       
        self.play(Write(text),self.camera.frame.animate.scale(0.8))
        self.wait()
        #镜头拉回
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        self.wait()
        #题目向上移动
        self.play(text.animate().scale(0.8).move_to(UP*20)) 
        #镜头拉近
        self.play(self.camera.frame.animate.scale(0.8).move_to([0,20,0]))
        #框框标记
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=7
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([0, 20, 0])
        self.play(Create(rectangle))
        #箭头引出
        #箭头引出
        arrow = Arrow(start=[0,15,0],end=[0,7,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本
        text1 = Tex(r"$\int ^{b}_{a}f\left( x\right) dx= F\left( b\right) -F\left( a\right) $"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([-15,11,0])
        self.play(Write(text1))
        #文本
        text2 = Tex(r"$F\left( x\right) =\int \dfrac{1}{1+\cos ^{2}x}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([0,3,0])
        self.play(Write(text2),self.camera.frame.animate.move_to([0,3,0]))
        self.wait(0.5)
        text3 = Tex(r"$=\dfrac{1}{\sqrt{2}}\arctan \dfrac{\tan x}{\sqrt{2}}+c$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([0,-2,0])
        self.play(Write(text3),self.camera.frame.animate.move_to([0,-2,0]))
        #框框标记
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=10
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([0, 0, 0])
        self.play(Create(rectangle1))
        #箭头引出
        arrow1 = Arrow(start=[0,-5,0],end=[0,-10,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow1),self.camera.frame.animate.move_to([0,-10,0]))
        #文本
        text4 = Tex(r"$\int _{0}^{\pi }\dfrac{1}{1+\cos ^{2}x}dx=F\left( \pi \right) -F\left( 0\right) =0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([0,-13,0])
        self.play(Write(text4),self.camera.frame.animate.move_to([0,-13,0]))
        #镜头拉回
        self.play(Restore(self.camera.frame))
        #框框闪动
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=4,height=5
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle2.move_to([15, -13, 0])
        self.play(Create(rectangle2))
        self.play(FadeOut(rectangle2))
        ##半透明框框扩展
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-8,-13,0])
        self.play(
            rectangle3.animate.stretch(10.0,dim=0)
        )
        text5 = Tex(r"$ >0$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).next_to(rectangle3,DOWN,buff=1)
        self.play(Write(text5))
         ##半透明框框扩展
        rectangle4=Rectangle(color=YELLOW,fill_opacity=0.4,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-15,-13,0])
        self.play(
            rectangle4.animate.stretch(2.0,dim=0)
        )
        #框框标记
      
        rectangle5=Rectangle(color=RED,fill_opacity=0,width=15,height=10
                            ,stroke_color=RED,stroke_width=20).move_to([-9,-15,0])
        self.play(Create(rectangle5))
       
        text6 = Tex(r"$ >0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).next_to(rectangle5,DOWN,buff=1)
        self.play(Write(text6))
        #文本
        text7 = Tex(r"$ ?$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(40.0).move_to([35,0,0])
        self.play(Write(text7))
        self.play(FadeOut(text7))
        text8 = Tex(r"$F\left( x\right) $\text{是原函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([35,20,0])
        self.play(Write(text8),self.camera.frame.animate.scale(0.8).move_to([35,20,0]))
        #箭头
        arrow2 = Arrow(start=[30,15,0],end=[30,7,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2),self.camera.frame.animate.move_to([30,7,0]))
        #文本
        text8 = Tex(r"$F\left( x\right) $\text{必连续}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([35,0,0])
        self.play(Write(text8),self.camera.frame.animate.move_to([35,0,0]))
        #箭头
        arrow3 = Arrow(start=[30,-3,0],end=[30,-10,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow3),self.camera.frame.animate.move_to([30,-10,0]))
        #文本
        text9 = Tex(r"$x=\dfrac{\pi }{2}$\text{是}$F\left( x\right) $\text{的间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([35,-15,0])
        self.play(Write(text9),self.camera.frame.animate.move_to([35,-15,0]))
         #文本
        text10 = Tex(r"$\int _{0}^{\pi }f\left( x\right) dx=\int ^{\frac{\pi }{2}}_{0}f\left( x\right) dx+\int ^{\pi }_{\frac{\pi }{2}}f\left( x\right) dx$"
                    ,color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(4.0).move_to([35,-20,0])
        self.play(Write(text10),self.camera.frame.animate.move_to([35,-20,0]))

        self.play(Restore(self.camera.frame))
        
        self.wait()

        

    

        
        


